﻿using movie.tool.library.time;

namespace movie.tool.module.response
{
    public class TokenInfo
    {
        /// <summary>
        /// 登录用户id
        /// </summary>
        public long? UserId { get; set; }
        /// <summary>
        /// 用户所属组织id,目前组织为店铺或者公司
        /// </summary>
        public long? OrgUnitId { get; set; }
        /// <summary>
        /// 令牌
        /// </summary>
        public string Access_token { get; set; }
        /// <summary>
        /// 整数,令牌过期时间，单位为秒
        /// </summary>
        public int Expires_in { get; set; }
        /// <summary>
        /// 刷新令牌
        /// </summary>
        public string Refresh_token { get; set; }
        /// <summary>
        /// 获取令牌时的时间戳。用来计算令牌是否过期
        /// </summary>
        public long Timestamp { get; set; }
        /// <summary>
        /// 是否快要过期了。如果到过期时间差小于10分钟就认为要过期了
        /// </summary>
        public bool NearExpired
        {
            get
            {
                long seconds = TimeUtils.GetTimeStamp() - Timestamp;
                return Expires_in - seconds <= 10 * 60;
            }
        }
    }
}
